package com.gxan.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.gxan.common.JsonResult;
import com.gxan.pojo.Recruitment;
import com.gxan.service.RecruitmentService;
import com.gxan.service.impl.RecruitmentServiceImpl;
import com.gxan.utils.DateUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet({"/recruitment/queryRecruitment","/recruitment/search"})
public class QueryRecruitmentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取前端传递过来的参数，这个需要做分页参数有page和limits
        String page = request.getParameter("page");
        String limits = request.getParameter("limit");
        String job_title = request.getParameter("job_title");
        String recruitment_type = request.getParameter("recruitment_type");
        String record_date = request.getParameter("record_date");
        String expiration_date = request.getParameter("expiration_date");
        Recruitment recruitment = new Recruitment();
        recruitment.setJob_title(job_title);
        recruitment.setRecruitment_type(recruitment_type);
        recruitment.setRecord_date(DateUtils.string2Date(record_date));
        recruitment.setExpiration_date(DateUtils.string2Date(expiration_date));
        //传递给service处理界面
        RecruitmentService recruitmentService = new RecruitmentServiceImpl();
        JsonResult jsonResult = recruitmentService.queryRecruitmentList(Integer.valueOf(page), Integer.valueOf(limits), recruitment);
        //返回数据到前端
        response.setContentType("application/json;charset=utf-8");
//        response.setCharacterEncoding("utf-8");
        response.getWriter().write(JSONObject.toJSONString(jsonResult));
        response.getWriter().flush();
        response.getWriter().close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
